<?php include_once __DIR__.'/../inc/userhead.html';?>
<?php include_once __DIR__.'/../inc/usermenu.html';?>
<!--右面板-->
<div class="main_panel">
  <!--头部-->
  <div class="panel_head">
    <ul class="title">
      <li><a href="javascript:;">账户安全</a></li>
    </ul>
  </div>
  <!--头部-->
  <div style="height:25px"></div>
  <!--修改账户密码开始-->
  <div class="panel_form">
      <form name="NewTelForm" method="post" action="/user/bindNewTel" class="layui-form">
      <p class="inl">
          <span>新手机号码<em class="import">*</em></span>
          <input name="newtel" required lay-verify="required" type="text" placeholder="新手机号码">
          <button type="button" lay-ignore onclick="sendsms(this,60,'newtel')">点击发送验证码</button>
      </p>
      <p class="inl">
          <span>登录密码<em class="import">*</em></span>
          <input name="password" required lay-verify="required" type="password" placeholder="登录密码">
      </p>
      <p class="inl">
          <span>手机验证码<em class="import">*</em></span>
          <input name="code" required lay-verify="required" type="text" placeholder="手机验证码">
      </p>
      <p class="inl addMarg"><a href="javascript:;" lay-submit  lay-filter="myform" class="save_btn" onclick="javascript:newtel();">确认修改</a></p>
      </form>
  </div>
  <div style="height:25px"></div>
  <!--修改账户密码开始-->
  <div class="panel_form">
      <form name="UserPasForm"  method="post" action="/user/remakePassword" class="layui-form">
      <p class="inl">
          <span>原密码<em class="import">*</em></span>
          <input name="newtel"  type="hidden" value="<?=$userinfo['phone'];?>">
          <input name="oldpassword" required lay-verify="required"  type="password" placeholder="请输入原密码">
      </p>
      <p class="inl">
          <span>新密码<em class="import">*</em></span>
          <input name="newpassword" required lay-verify="required"  type="password" placeholder="请输入新密码">
      </p>
      <p class="inl">
          <span>确认密码<em class="import">*</em></span>
          <input name="repassword" required lay-verify="required"  type="password" placeholder="请输入确认密码">
      </p>
      <p class="inl">
          <span>手机验证码<em class="import">*</em></span>
          <input name="code" required lay-verify="required"  type="password" placeholder="手机验证码">
          <button type="button" lay-ignore onclick="sendsms(this,60,'remake')">点击发送验证码</button>
      </p>
      <p class="inl addMarg"><a href="javascript:;" lay-submit  lay-filter="myform" class="save_btn">确认修改</a></p>
      </form>
  </div>
  <!--修改账户密码结束-->
</div>
<!--右面板-->
</div>
<script type='text/javascript'>

//发送短信
function sendsms(e,second,type){
    var oldpassword = "";
    if(type == "remake"){
        var newtel = document.UserPasForm.newtel.value;
        oldpassword = document.UserPasForm.oldpassword.value;
        if(!oldpassword){
            layer.msg('请填写原密码');
            return false;
        }
    }else{
        var newtel = document.NewTelForm.newtel.value;
    }
    var reg = /^1[0-9]{10}$/;
    if(!reg.test(newtel)){
        layer.msg('请填写正确的手机号');
        return false;
    }

      $.ajax({
          url:"<?=url('publics/sendSms');?>",
          method:"post",
          dataType:"json",
          data:{phone:newtel,type:type,oldpassword:oldpassword},
          success:function(rs){
              if(rs.code!=0){
                  layer.msg(rs.msg);
                  return false;
              }
              $(e).attr("disabled");
              $(e).text("重新发送(" + second + ")");
              var index = setInterval(function(rs) {
                  countdown = parseInt(/(\d+)/gi.exec($(e).text()));
                  if (countdown == 0) {
                      $(e).removeAttr("disabled");
                      $(e).text("点击发送验证码");
                      clearInterval(index);
                      return false;
                  } else {
                      $(e).attr("disabled", true);
                      countdown--;
                      $(e).text("获取验证码(" + countdown + ")");
                  }
              },1000);
          }
      });
  }

</script>
<?php include_once __DIR__.'/../inc/foot.html';?>
